export type NodeEnv = 'development' | 'production' | 'test';

export function getNodeEnv(): NodeEnv {
  const env = process.env.NODE_ENV as NodeEnv | undefined;

  if (!env) {
    // Sets a default if NODE_ENV is undefined.
    return 'development';
  }

  if (!['development', 'production', 'test'].includes(env)) {
    throw new Error(`Invalid NODE_ENV value: ${env}`);
  }

  return env;
}

export function isDevelopment(): boolean {
  return getNodeEnv() === 'development';
}

export function isProduction(): boolean {
  return getNodeEnv() === 'production';
}

export function isTest(): boolean {
  return getNodeEnv() === 'test';
}